﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<style>

    .layui-iconpicker-body.layui-iconpicker-body-page .hide {
        display: none;
    }
</style>
<script>
    layui.use(['jquery', 'form', 'laydate', 'common', 'iconPickerFa', 'optimizeSelectOption'], function () {
        var form = layui.form,
            $ = layui.$,
            iconPickerFa = layui.iconPickerFa,
            common = layui.common,
            laydate = layui.laydate;
        var keyValue = $.request("keyValue");
        //权限字段
        common.authorizeFields('adminform');
        var event = $.request("event");
        $(function () {
            initControl();
            if (event == "edit") {
                common.ajax({
                    url: "/SystemManage/Module/GetFormJson",
                    dataType: "json",
                    data: { keyValue: keyValue },
                    async: false,
                    success: function (data) {
                        common.val('adminform', data);
                        if (!!data.F_Icon) {
                            iconPickerFa.checkIcon('iconPicker', data.F_Icon);
                        }
                    }
                });
            }
            else {
                if (!!keyValue) {
                    $('#F_ParentId').val(keyValue);
                }
            }
            form.render();
        });
        wcLoading.close();
        function initControl() {
            $("#F_ParentId").bindSelect({
                url: "/SystemManage/Module/GetTreeSelectJson",
            });
        }
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            // 单击之后提交按钮不可选,防止重复提交
            $('.site-demo-active').addClass('layui-btn-disabled');
            $('.site-demo-active').attr('disabled', 'disabled');
            var postData = data.field;
            if (!postData["F_EnabledMark"]) postData["F_EnabledMark"] = false;
            if (!postData["F_IsMenu"]) postData["F_IsMenu"] = false;
            if (!postData["F_IsFields"]) postData["F_IsFields"] = false;
            if (!postData["F_IsPublic"]) postData["F_IsPublic"] = false;
            if (!postData["F_IsExpand"]) postData["F_IsExpand"] = false;
            common.submitForm({
                url: event == "edit" ? "/SystemManage/Module/SubmitForm?keyValue=" + keyValue : "/SystemManage/Module/SubmitForm",
                param: postData,
                success: function () {
                    common.parentreload("data-search-btn");
                }
            })
            return false;
        });
        //select验证
        form.verify({
            required: function (value, item) {
                var msg = "必填项不能为空";
                value = $.trim(value);
                var isEmpty = !value || value.length < 1;
                // 当前验证元素是select且为空时,将页面定位至layui渲染的select处，或自定义想定位的位置
                if (item.tagName == 'SELECT' && isEmpty) {
                    $("html").animate({
                        scrollTop: $(item).siblings(".layui-form-select").offset().top - 74
                    }, 50);
                }
                if (isEmpty) {
                    return msg;
                }
            }
        });
        iconPickerFa.render({
            // 选择器，推荐使用input
            elem: '#iconPicker',
            // fa 图标接口
            url: "/lib/font-awesome-4.7.0/less/variables.less",
            // 是否开启搜索：true/false，默认true
            search: true,
            // 是否开启分页：true/false，默认true
            page: true,
            // 每页显示数量，默认12
            limit: 12,
            // 点击回调
            click: function (data) {
                //console.log(data);
                $("#F_Icon").val("fa " + data.icon);
            },
            // 渲染成功后的回调
            success: function (d) {
                //console.log(d);
            }
        });
    });
    function clearIcon() {
        layui.use(['iconPickerFa'], function () {
            layui.iconPickerFa.checkIcon('iconPicker', "");
            $("#F_Icon").val("");
        });
    }
</script>
<body>
    <div class="layuimini-container">
        <div class="layuimini-main">
            <div class="layui-form layuimini-form" lay-filter="adminform">
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label required">上级</label>
                    <div class="layui-input-block">
                        <select id="F_ParentId" name="F_ParentId"  lay-verify="required"  lay-search>
                            <option value="0" selected>父节点</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label required">编号</label>
                    <div class="layui-input-block">
                        <input type="text" id="F_EnCode" name="F_EnCode" maxlength="50" lay-verify="required" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label required">名称</label>
                    <div class="layui-input-block">
                        <input type="text" id="F_FullName" name="F_FullName" maxlength="50" lay-verify="required" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label">连接</label>
                    <div class="layui-input-block">
                        <input type="text" id="F_UrlAddress" name="F_UrlAddress" maxlength="50" class="layui-input ">
                    </div>
                </div>
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label required">目标</label>
                    <div class="layui-input-block">
                        <select id="F_Target" name="F_Target" lay-verify="required">
                            <option value="">==请选择==</option>
                            <option value="expand" title="expand">无页面</option>
                            <option value="iframe" title="iframe">框架页</option>
                            <option value="open" title="open">弹出页</option>
                            <option value="blank" title="blank">新窗口</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label">图标</label>
                    <div class="layui-input-block" style="padding-right: 70px;">
                        <input type="text" id="F_Icon" name="F_Icon" class="layui-input layui-hide">
                        <input type="text" id="iconPicker" @*value="fa fa-file-image-o"*@ lay-filter="iconPicker" class="hide">
                        <button class="layui-btn layui-btn-warm"  onclick="clearIcon()" style="position: absolute;top: 0;right: 6px;cursor: pointer;" >清除图标</button>
                    </div>
                </div>
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label required">显示顺序</label>
                    <div class="layui-input-block">
                        <input type="number" pattern="[0-9]*" id="F_SortCode" name="F_SortCode" lay-verify="required|number" oninput="if(value.length>8)value=value.slice(0,8)" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label">选项</label>
                    <div class="layui-input-block">
                        <input id="F_IsMenu" name="F_IsMenu" type="checkbox" value="true" title="菜单">
                        <input id="F_IsExpand" name="F_IsExpand" type="checkbox" value="true" title="展开">
                        <input id="F_IsPublic" name="F_IsPublic" type="checkbox" value="true" title="公共">
                        <input id="F_IsFields" name="F_IsFields" type="checkbox" value="true" title="字段">
                        <input type="checkbox" name="F_EnabledMark" id="F_EnabledMark" checked="" value="true" title="有效">
                    </div>
                </div>
                <div class="layui-form-item layui-form-text layui-hide">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-block">
                        <textarea id="F_Description" name="F_Description" class="layui-textarea" placeholder="请输入介绍"></textarea>
                    </div>
                </div>
                <div class="layui-form-item layui-hide">
                    <button class="layui-btn site-demo-active" lay-submit id="submit" lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>

</body>